// src\router\IndexRouter.js
// 路由统一配置

import React from 'react'
import { Route, Switch, Redirect, HashRouter } from 'react-router-dom'
// 引入路由组件
import Login from '@/views/Login/Login'
import NewsSendBox from '@/views/sendbox/NewsSendBox'
import News from '@/views/news/News'
import Detail from '@/views/news/Detail'

export default function IndexRouter() {
    return (
   
            <HashRouter>
                <Switch>
                    <Route path='/login' component={Login}></Route>
                    {/* 添加游客可以访问的路由，跳过token检查 */}
                    <Route path='/news' component={News}></Route>
                    <Route path='/detail/:id' component={Detail}></Route>
                    {/* 如果登录了就去正确的路由组件，未登录就重定向到登录页面 */}
                    <Route path='/' render={() =>
                        localStorage.getItem('token') ? <NewsSendBox></NewsSendBox> : <Redirect to='/login'></Redirect>
                    }></Route>

                </Switch>
            </HashRouter>
    
    )
}
